<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<%@ include file="/static/include/common.inc"%>
<link rel="stylesheet" href="static/admin/css/layui.css">
<link rel="stylesheet" href="static/layui_v2.2.3/css/zbyui.css">
<link rel="stylesheet" href="static/admin/css/main.css" media="all">
<script src="static/js/jquery-1.11.2.js"></script>
<script src="static/layui_v2.2.3/layui.js" charset="utf-8"></script>
</head>
<body>
  <ul class="layui-tab-title">
    <li class="layui-this">活动管理</li>
  </ul>
	<div class="layui-tab-content">
		<div class="layui-tab-item layui-show" style="margin: 10px">
			<div class="demoTable">
				<div class="layui-inline">
					<input class="layui-input" name="articleName" id="articleName" autocomplete="off" placeholder="请输入活动名称">
				</div>
				<button class="layui-btn" data-type="reload" id="zby-search">搜索</button>
				<!-- <button class="layui-btn" data-type="reload" id="zby-type-manage">类型管理</button> -->
				<button class="layui-btn" data-type="reload" style="float: right;" id="addArticle">添加</button>
			</div>
			<div>
				<table class="layui-table" id="zby-table" lay-filter="tablename" >
				
				</table>
			</div>
			<!-- <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a> -->
			<script type="text/html" id="barDemo">
           		<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
           		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
			</script>
		</div>
	</div>
	<script type="text/javascript">
		layui.use('table', function() {
			var table = layui.table;
			//第一个实例
			var tableObj = table.render({
			    elem: '#zby-table',
			    url: 'admin/activity/pageList.do', //数据接口,
			    page: true, //开启分页,
			    where: {title:$("#articleName").val()},
			    cols: [[ //表头
			      {field: 'id', title: 'ID',sort: true, fixed: 'left'}
			      ,{field: 'title', title: '活动名称', }
			      ,{field: 'releaseTimeStr', title: '发布时间', sort: true}
			      ,{field: 'readNum', title: '阅读次数' } 
			      ,{field: 'typeStr', title: '类型' }
			      ,{field: 'statusStr', title: '状态'}
			      ,{fixed: 'right',align:'center', toolbar: '#barDemo'}
			    ]],
			    id:	"zby-reload",
			    response:{
			    	
			    }
			  });
			
			$("#zby-search").bind("click",function(){
				table.reload("zby-reload",{
					page: {
				          curr: 1 //重新从第 1 页开始
				    },
					where:{
						title:$("#articleName").val()
					}
				});
			}) 
			//监听表格复选框选择
			table.on('checkbox(tablename)', function(obj) {
				console.log(obj)
			});
			
			$("#addArticle").bind("click",function(){
				layer.open({
					skin : 'layui-layer-lan',
					title : '新增活动',
					shadeClose : false,
					move : false,
					closeBtn : 2,
					type : 2,
					area : [ '1000px', '700px' ],
					fixed : false, //不固定
					maxmin : true,
					content : 'admin/activity/activityUpdate.do'
				});
			})
			$("#zby-type-manage").bind("click",function(){
				layer.open({
					skin : 'layui-layer-lan',
					title : '类型管理页',
					shadeClose : false,
					move : false,
					closeBtn : 2,
					type : 2,
					area : [ '1000px', '700px' ],
					fixed : false, //不固定
					maxmin : true,
					content : 'admin/typeManage/index.do'
				});
			})
			//监听工具条
			table.on('tool(tablename)', function(obj) {
				var data = obj.data;
				/* if (obj.event === 'detail') {//查看
					layer.open({
						type : 2,
						title : data.articleName + '详情',
						shadeClose : false,
						move : false,
						type : 2,
						area : [ '1000px', '700px' ],
						maxmin : true,
						closeBtn : 0,
						content : 'admin/article/articleDetail.do?articleId=' + data.articleId,
						btn : [ '关闭' ],
						yes : function() {
							layer.closeAll();
						}
					});
				} else  */if (obj.event === 'del') {//删除
					layer.confirm('真的删除行么', function(index) {
						$.ajax({
							type : "post",
							url : "admin/activity/activityDel.do",
							data : {"id" : data.id},
							async: false,
							success : function(result) {
								if (result.code == 1) {
									obj.del();
									layer.msg(result.msg);
								} else {
									layer.msg(result.msg);
								}
							}
						});
						layer.close(index);
					});
				} else if (obj.event === 'edit') {//编辑
					layer.open({
						skin : 'layui-layer-lan',
						title : data.title+'编辑',
						shadeClose : false,
						move : false,
						closeBtn : 2,
						type : 2,
						area : [ '1000px', '700px' ],
						fixed : false, //不固定
						maxmin : true,
						content : 'admin/activity/activityUpdate.do?id=' + data.id 
					});
				}
			});
		});

		$(function() {
			$(".layui-tab-title").children("li").click(
					function() {
						clear();
						$(this).attr("class", "layui-this");

						$("ul li.layui-this").index();
						$(".layui-tab-content").children("div").eq(
								$("ul li.layui-this").index()).attr("class",
								"layui-tab-item layui-show");
					})

		})
		function clear() {
			$(".layui-tab-title").children("li").each(function() {
				$(this).attr("class", "");
			})
			$(".layui-tab-content").children("div").each(function() {
				$(this).attr("class", "layui-tab-item");
			})

		}
	</script>
</body>
</html>